# -*- coding: utf-8 -*-

import os
if '__file__' in globals():
    import os,sys
    sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
    
from dezero import Variable
import dezero.functions  as F
from dezero.utils import plot_dot_graph
import numpy as np

# x0 = Variable(np.array(1.0))
# x1 = Variable(np.array(1.0))
# y = x0 + x1
# y.backward()
#
# x0.name='x0'
# x1.name='x1'
# y.name='y'
# print(get_dot_graph(y))
# plot_dot_graph(y)

x = Variable(np.array(1.0))
y = F.tanh(x)
x.name = 'x'
y.name = 'y'
y.backward(create_graph=True)

iters = 3 #求n阶导数
for i in range(iters):
    gx = x.grad
    x.cleargrad()
    gx.backward(create_graph=True)

#绘制计算图
gx = x.grad
gx.name = 'gx'+str(iters+1)
plot_dot_graph(gx,verbose=False,to_file='tanh.png')


